home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-06-19 | 7.7 KB | 232 lines |
- /*
- *
- */
-
- package symantec.itools.db.awt;
-
- import java.util.*;
- import symjava.sql.*;
- import java.lang.*;
- import symantec.itools.db.net.*;
- import symantec.itools.db.pro.*;
-
- public class RadioBox extends java.awt.CheckboxGroup implements ProjLink
- {
- /**
- * The ProjBinder object which this component can use to get data from
- * the server, or change data at the database server.
- */
- private ProjBinder m_ProjBinder;
-
- private RelationView m_relView;
- private String m_projection;
- private int m_treatBlankAs = 0;
- private boolean m_DynamicUpdate = false;
-
- private Vector rbkVector = new Vector();
- private java.awt.Container m_Container;
-
- /**
- * Constructs a new TextField.
- */
- public RadioBox(java.awt.Container c)
- {
- super();
- m_Container = c;
- }
-
- /**
- * Implement the ProjLink interface function, init().
- * This function is called when the control is first bound to data.
- *
- * @param binder The ProjBinder binder object which this component can use
- * to change data at the database server.
- */
- public void init (ProjBinder binder)
- {
- m_ProjBinder = binder;
-
- }
-
- public RelationView getRelView()
- {
- return m_relView;
- }
-
- public String getProjection()
- {
- return m_projection;
- }
-
- public void setTreatBlankAs(String blank)
- {
- if (new String(blank).toUpperCase().equals("DEFAULT"))
- {
- m_treatBlankAs = RelationView.SETBLANKTODEFAULT;
- }
- else if (new String(blank).toUpperCase().equals("NULL"))
- {
- m_treatBlankAs = RelationView.SETBLANKTONULL;
- }
- else if (new String(blank).toUpperCase().equals("BLANK"))
- {
- m_treatBlankAs = RelationView.SETBLANKTOEMPTY;
- }
- }
-
- public void setBinding(RelationView relView, String projection)
- {
- m_relView = relView;
- m_projection = projection;
- try
- {
- int projectionNumber = relView.findProjByName(projection);
- relView.bindProj(projectionNumber, this);
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from RadioBox.setBinding: "
- + Ex.getMessage());
- }
- }
-
- void addCheckboxes(java.awt.Container c)
- {
- int compCnt = c.countComponents();
- java.awt.Component[] compArray = new java.awt.Component[compCnt];
- compArray = c.getComponents();
- for (int loops = 0; loops < compArray.length; loops++)
- {
- if (compArray[loops] instanceof java.awt.Checkbox)
- {
- if (this.equals(((java.awt.Checkbox)compArray[loops]).getCheckboxGroup()))
- {
- rbkVector.addElement(compArray[loops]);
- }
- }
- }
- }
-
- /**
- * Implement the ProjLink interface function, notifyDataChange().
- * This function is called when the projection's data changes at the database.
- *
- * @param binder The ProjBinder binder object which this component can use
- * to get or change data at the database server.
- */
- public void notifyDataChange(ProjBinder binder)
- {
- int rbCurrent = 0;
- boolean itemfound = false;
-
- addCheckboxes(m_Container);
-
- try
- {
- while (rbCurrent < rbkVector.size())
- {
- symantec.itools.db.awt.RadioButton rb = (symantec.itools.db.awt.RadioButton)rbkVector.elementAt(rbCurrent);
- if (rb != null)
- {
- if (rb.getLabel().equals(binder.getStringValue()))
- {
- itemfound = true;
- break;
- }
- else
- {
- rbCurrent++;
- }
- }
- }
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from RadioBox.notifyDataChange: "
- + Ex.getMessage());
- }
- catch (java.io.IOException Ex)
- {
- raiseException(
- "IOException from RadioBox.notifyDataChange: "
- + Ex.getMessage());
- }
- if (!itemfound)
- {
- setCurrent(null);
- }
- }
-
- public boolean notifySetData(ProjBinder binder) throws SQLException
- {
- return ( notifyStateChange() );
- }
-
- boolean notifyStateChange()
- {
- if (getCurrent() == null)
- {
- try
- {
- if (m_ProjBinder != null && m_ProjBinder.isWritable())
- {
- m_ProjBinder.setValueFromString("", 0, m_treatBlankAs);
- }
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from RadioBox.notifyStateChange: "
- + Ex.getMessage());
- return false;
- }
- catch (java.io.IOException Ex)
- {
- raiseException(
- "IOException from RadioBox.notifyStateChange: "
- + Ex.getMessage());
- return false;
- } }
- return true;
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: raiseException //
- // //
- // PURPOSE: //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- void raiseException(String text)
- {
- System.out.println(text);
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: setDynamicUpdate //
- // //
- // PURPOSE: //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- public void setDynamicUpdate(boolean update)
- {
- m_DynamicUpdate = update;
- }
- }